//
//  MineToolCard.m
//  BaseProject
//
//  Created by 王盼盼 on 2024/10/30.
//  Copyright © 2024 wangpanpan. All rights reserved.
//

#import "MineToolCard.h"
#import "MineTopBottomItem.h"
@interface MineToolCard ()
@property(nonatomic, strong) UILabel *nameLabel;
@property(nonatomic, strong) NSMutableArray<MineItemModel *> *itemModels;
@end

@implementation MineToolCard
- (void)makeUI {
    [super makeUI];
    self.layer.cornerRadius = 10;
    [self addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(16);
    }];
    
    {
        NSArray *order_pics = @[ImageName.mine_huangdaojiri, ImageName.mine_xiweianpaibiao, ImageName.mine_beihunjihua];
        NSArray *order_titles = @[@"黄道吉日", @"席位安排表", @"备婚计划"];
        NSArray<NSNumber *> *order_actions = @[@(ItemActionToolHuangDaoJiRi), @(ItemActionToolXiWeiAnPaiBiao), @(ItemActionToolBeiHunJiHua)];
        NSMutableArray<MineItemModel *> *orderItems = [NSMutableArray array];
        CGFloat orinY = 54;
        for (NSInteger index = 0; index < order_titles.count; index ++) {
            MineItemModel *item = [[MineItemModel alloc]init];
            item.style = ItemStyleOrder;
            item.action = order_actions[index];
            
            item.picUrl = order_pics[index];
            item.title = order_titles[index];
            item.picSize = CGSizeMake(24, 24);
            item.titleFont = kFontRegular(12);
            item.titleColor = rgba(47, 47, 52, 1);
            item.itemMargin = 6;
            [orderItems addObject:item];
        }
        CGFloat itemWidth = ceil(self.width / order_titles.count);
        for (NSInteger index = 0; index < orderItems.count; index ++) {
            MineTopBottomItem *item = [[MineTopBottomItem alloc]initWithFrame:CGRectMake(itemWidth * index, orinY, itemWidth, self.height * 0.5)];
            [self addSubview:item];
            item.data = orderItems[index];
            // 手势
            item.tag = self.itemModels.count + index;
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickItem:)];
            item.userInteractionEnabled = YES;
            [item addGestureRecognizer:tap];
        }
        [self.itemModels addObjectsFromArray:orderItems];
    }
    
    {
        NSArray *order_pics = @[ImageName.mine_hunyingdengjichu, ImageName.mine_shiyanzhiciku, ImageName.mine_jieqinyouxi, ImageName.mine_hunliyusuanbiao];
        NSArray *order_titles = @[@"婚礼登记处", @"誓言致辞库", @"接亲游戏", @"婚礼预算表"];
        NSArray<NSNumber *> *order_actions = @[@(ItemActionToolHunLiDengJiChu), @(ItemActionToolShiYanZhiCiKu), @(ItemActionToolJieQinYouXi), @(ItemActionToolHunLiYuSuanBiao)];
        NSMutableArray<MineItemModel *> *orderItems = [NSMutableArray array];
        CGFloat orinY = 120;
        for (NSInteger index = 0; index < order_titles.count; index ++) {
            MineItemModel *item = [[MineItemModel alloc]init];
            item.style = ItemStyleOrder;
            item.action = order_actions[index];
            
            item.picUrl = order_pics[index];
            item.title = order_titles[index];
            item.picSize = CGSizeMake(24, 24);
            item.titleFont = kFontRegular(12);
            item.titleColor = rgba(47, 47, 52, 1);
            item.itemMargin = 6;
            [orderItems addObject:item];
        }
        CGFloat itemWidth = ceil(self.width / order_titles.count);
        for (NSInteger index = 0; index < orderItems.count; index ++) {
            MineTopBottomItem *item = [[MineTopBottomItem alloc]initWithFrame:CGRectMake(itemWidth * index, orinY, itemWidth, self.height * 0.5)];
            [self addSubview:item];
            item.data = orderItems[index];
            // 手势
            item.tag = self.itemModels.count + index;
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickItem:)];
            item.userInteractionEnabled = YES;
            [item addGestureRecognizer:tap];
        }
        [self.itemModels addObjectsFromArray:orderItems];
    }
}
- (void)bindViewModel {
    [super bindViewModel];
    self.nameLabel.text = @"热门工具";
}
#pragma mark - click
- (void)clickItem:(UITapGestureRecognizer *)ges {
    !self.clickAction ?: self.clickAction(self.itemModels[ges.view.tag]);
}
#pragma mark - lazy
- (UILabel *)nameLabel {
    if (!_nameLabel) {
        UILabel *lab = [[UILabel alloc]init];
        lab.font = kFontMedium(16);
        lab.textColor = rgba(47, 47, 52, 1);
        lab.textAlignment = NSTextAlignmentLeft;
        lab.numberOfLines = 1;
        _nameLabel = lab;
    }
    return _nameLabel;
}
- (NSMutableArray<MineItemModel *> *)itemModels {
    if (!_itemModels) {
        _itemModels = [NSMutableArray array];
    }
    return _itemModels;
}
@end
